package com.hmall.clients.consumer;

import com.hmall.clients.service.SearchService;
import com.hmall.common.pojo.Item;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.script.Bindings;

@Component
public class SpringRabbitListener {
    @Autowired
    private SearchService searchService;
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "hmall.topic.query"),
            exchange = @Exchange(name = "hmall.topic", type = ExchangeTypes.TOPIC),
            key = "putaway"
    ))
    void putaway(Item item){
        searchService.putaway(item);
    }


    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "hmall.topic.query"),
            exchange = @Exchange(name = "hmall.topic", type = ExchangeTypes.TOPIC),
            key = "soldout"
    ))
    void soldout(Item item){
        searchService.soldout(item);
    }
}
